package com.ctlele.team.space.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.ctlele.team.space.R;

public class InputDialog extends Dialog {

    private Button mOk;

    private Button mCancel;

    private EditText mDirName;

    private TextView mTitle;

    private String mOkText = "确定";

    private String mCancelText = "取消";

    private String mTitleText = "输入";

    private View.OnClickListener mCancelOnClick = (view) -> dismiss();

    private View.OnClickListener mOkOnClick = view -> {
    };

    public InputDialog(@NonNull Context context) {
        super(context);
    }

    public void setOkText(String str) {
        mOkText = str;
    }

    public void setCancelText(String str) {
        mCancelText = str;
    }

    public void setOnCancel(View.OnClickListener listener) {
        mCancelOnClick = listener;
    }

    public void setOnOk(View.OnClickListener listener) {
        mOkOnClick = listener;
    }

    public void setTitle(String title) {
        mTitleText = title;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_input_layout);
        mOk = findViewById(R.id.ok);
        mCancel = findViewById(R.id.cancel);
        mDirName = findViewById(R.id.ed_file_dir_name);
        mTitle = findViewById(R.id.text_title);
        this.setCanceledOnTouchOutside(false);
        initData();
    }

    private void initData() {
        mOk.setText(mOkText);
        mCancel.setText(mCancelText);
        mOk.setOnClickListener(mOkOnClick);
        mCancel.setOnClickListener(mCancelOnClick);
        mTitle.setText(mTitleText);
    }

    public String getText() {
        return mDirName.getText().toString();
    }
}
